/**
 * Created by Freeman on 2016/6/30.
 */
"use strict";

import {getCookie} from '../../utils/authService'
import {LOGIN_SUCCESS,USERINFO_SUCCESS,USERINFO_FAILURE,LOGOUT_SUCCESS,UPDATE_USER_SUCCESS} from '../types'

const state = {
    token: getCookie('token') || null ,
    user : null
}

const mutations = {
    [LOGIN_SUCCESS](state,action){
        state.token = action.token
    },
    [USERINFO_SUCCESS](state,action){
        state.user = action.user
    },
    [USERINFO_FAILURE](state,action){
        state.user = null
    },
    [LOGOUT_SUCCESS](state,action){
        state.token = getCookie('token') || null
        state.user = null
        state.token = null
    },
    [UPDATE_USER_SUCCESS](state,action){
        state.user = action.user
    }
}

export default {
    state,
    mutations
}